package com.redis.springbootredis.controller;

import com.redis.springbootredis.entity.OrderTest;
import com.redis.springbootredis.service.impl.OrderTestServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author
 * @create 2020-11-02 11:30
 */
@Controller
public class SessionController {

    @Autowired
    OrderTestServiceImpl orderTestService;

    @Value("${server.port}")
    String port;


    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response, HttpSession session){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        OrderTest user = orderTestService.getOrderTest(username, password);
        if(user != null){
            System.out.println("cg");
            session.setAttribute("user",user.getUsername());
            System.out.println("port:"+port);
            return "show";
        }else{
            System.out.println("登录失败");
            return "";
        }
    }
}
